// miniprogram/pages/wait/detail.js
import config from "../../config/index";
import U from "../../utils/index";
import * as R from "ramda";
import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog';

const reqDetail = data => U.handleRequest({}, () => Promise.all([
  U.reqPost({
    url:'/task/task_list',
    data
  }),
  U.reqPost({
    url:'/task/task_log_list',
    data
  })
]))
const handleReqRevoke = data => U.handleRequest({}, () => U.reqPost({
    url:'/task/uncomlete_task',
    data
  })
);
Page({

  /**
   * 页面的初始数据
   */
  data: {
    taskId: null,
    isShowPage: false,
    pageData: null,
    taskLogs: null,
    taskTypeNames: config.taskTypeNames,
    orderType: config.orderType,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ taskId: options.taskId });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    R.compose(
      U.fork,
      R.map(
        results => this.setData({
          pageData: R.clone(results[0].data.list[0]),
          taskLogs: R.clone(results[1].data.list),
          isShowPage: true,
        }),
      ),
      () => reqDetail({ task_id: this.data.taskId })
    )();
  },
  onClickRevoke(e) {
    R.composeP(
      R.compose(
        U.fork,
        R.map(() => this.onShow()),
        () => handleReqRevoke({ task_id: this.data.taskId }),
      ),
      () => Dialog.confirm({ message: '是否确认撤销完成任务？' })
    )();
  },
  //点击图片预览图片
  onClickImg(e){
    (path => wx.previewImage({
      urls: [ path ],
      current: path
    }))(this.data.taskLogs[e.target.dataset.index].complete_image_url);
  },
})
